import { service } from '@/utils/axios'

const BASE_URL = '/v1/menus'
// 新增
export function addMenu(data: any): Promise<any> {
  return service({
    url: BASE_URL,
    method: 'post',
    data
  })
}

// 更新
export function updateMenu(id: any, data: any): Promise<any> {
  return service({
    url: `${BASE_URL}/${id}`,
    method: 'put',
    data
  })
}

export function deleteMenu(id: any): Promise<any> {
  return service({
    url: `${BASE_URL}/${id}`,
    method: 'delete'
  })
}

export function getMenuList(params: any) {
  return service({
    url: BASE_URL,
    method: 'get',
    params
  })
}

export function getMenuOptionList(onlyParent: any): any {
  return service({
    url: `${BASE_URL}/options`,
    method: 'get',
    params: {
      onlyParent: onlyParent
    }
  })
}

export function getRoleMenuOptionList(): any {
  return service({
    url: `${BASE_URL}/role/options`,
    method: 'get'
  })
}

export function getMenuRouterList() {
  return service({
    url: `${BASE_URL}/routes`,
    method: 'get'
  })
}

export function getMenuForm(id: any): Promise<any> {
  return service({
    url: `${BASE_URL}/${id}/form`,
    method: 'get'
  })
}

export function getRoleDataPermissionOptions(): any {
  return service({
    url: `${BASE_URL}/role/data-permission/options`,
    method: 'get'
  })
}

export function getMeRouter(): Promise<any> {
  return service({
    url: `${BASE_URL}/routes`,
    method: 'get'
  })
}
